package cn.stylefeng.guns.modular.rest.transport;


import cn.stylefeng.guns.modular.basic.entity.BasicOperate;
import cn.stylefeng.guns.modular.basic.entity.BasicPutgoods;
import cn.stylefeng.guns.modular.basic.model.result.BasicPutgoodsResult;
import cn.stylefeng.guns.modular.basic.service.BasicOperateService;
import cn.stylefeng.guns.modular.basic.service.BasicPutgoodsService;
import cn.stylefeng.guns.modular.order.model.params.OrderTransportParam;
import cn.stylefeng.guns.modular.rest.aop.UserAop;
import cn.stylefeng.guns.modular.transport.model.params.TransportPlateStoreParam;
import cn.stylefeng.guns.modular.transport.model.result.TransportPlateStoreResult;
import cn.stylefeng.guns.modular.transport.service.TransportPlateStoreService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/rest/transportPlateStore")
public class RestTransportPlateStoreController {

    @Autowired
    private UserAop userAop;

    @Autowired
    private TransportPlateStoreService transportPlateStoreService;

    @Autowired
    private BasicPutgoodsService basicPutgoodsService;

    @Autowired
    private BasicOperateService basicOperateService;


    @ResponseBody
    @RequestMapping("/listAll")
    public List<TransportPlateStoreResult> listAll(TransportPlateStoreParam param ) {
        return this.transportPlateStoreService.findListBySpec(param);
    }


    @ResponseBody
    @RequestMapping("/getNoBindList")
    public ResponseData getNoBindList(Long operateIdc, OrderTransportParam orderTransportParam) {
        User user = userAop.getUser();
//        paramCondition.setDeliverId(user.getDeliverId());
//        paramCondition.setDeptId(user.getDeptId());
//        paramCondition.setCreateUser(user.getUserId());
        if(operateIdc != null) {
            BasicOperate Operate = basicOperateService.getById(operateIdc);
            orderTransportParam.setDeliverId(Operate.getDeliverId());
            orderTransportParam.setDeptId(Operate.getDeptId());
        } else {
            operateIdc = user.getOperateId();
            orderTransportParam.setDeliverId(user.getDeliverId());
            orderTransportParam.setDeptId(user.getDeptId());
        }
        orderTransportParam.setTstate("dispatch");

        return this.transportPlateStoreService.noBindList(operateIdc,orderTransportParam);
    }

    @ResponseBody
    @RequestMapping("/getBindList")
    public List<TransportPlateStoreResult> getBindList(TransportPlateStoreParam transportPlateStoreParam) {
        User user = userAop.getUser();
//        transportPlateStoreParam.setDeliverId(user.getDeliverId());
//        transportPlateStoreParam.setDeptId(user.getDeptId());
//        transportPlateStoreParam.setCreateUser(user.getUserId());
        transportPlateStoreParam.setUserId(user.getUserId());
        return this.transportPlateStoreService.findListBySpec(transportPlateStoreParam);
    }

    @RequestMapping("/bind")
    @ResponseBody
    public ResponseData bind(TransportPlateStoreParam transportPlateStoreParam) {
        User user = userAop.getUser();
        transportPlateStoreParam.setPlateNumber(user.getAccount());
        transportPlateStoreParam.setUserId(user.getUserId());
        transportPlateStoreParam.setDeliverId(user.getDeliverId());
        transportPlateStoreParam.setDeptId(user.getDeptId());
        transportPlateStoreParam.setCreateTime(new Date());
        transportPlateStoreParam.setCreateUser(user.getUserId());
        transportPlateStoreParam.setUpdateUser(user.getUserId());
        transportPlateStoreParam.setUpdateTime(new Date());
        this.transportPlateStoreService.add(transportPlateStoreParam);
        return ResponseData.success();
    }

    @RequestMapping("/noBind")
    @ResponseBody
    public ResponseData noBind(TransportPlateStoreParam transportPlateStoreParam) {
        this.transportPlateStoreService.delete(transportPlateStoreParam);
        return ResponseData.success();
    }

    @RequestMapping("/setOrd")
    @ResponseBody
    public ResponseData setOrd(TransportPlateStoreParam transportPlateStoreParam) {
        this.transportPlateStoreService.setOrd(transportPlateStoreParam);
        return ResponseData.success();
    }


}
